<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Feed
 * @author		Jade Xia
 * @copyright	Copyright (c) 2010 - 2011 天夏网络.
 * @link		http://www.tianxianet.com
 */
class Feed extends Controller
{
	
	function Feed()
	{
		parent::Controller();
		$this->load->database();
		$this->load->model('com_model');
		$this->load->helper('file');
	}
	
	function index()
	{
		$data = array(
			'product'		=> $this->common_model->get_records('SELECT id,title,content,create_date FROM '.$this->db->dbprefix.'product WHERE is_trash = 0 ORDER BY seqorder DESC,id DESC LIMIT 200')
		);
		header("Content-Type:text/xml; charset=utf-8");
		$this->load->view(TPL_FOLDER."rss",$data);
	}
	
	function rss()
	{
		$data = array(
			'news'		=> $this->common_model->get_records('SELECT id,title,content,create_date FROM '.$this->db->dbprefix.'news WHERE is_trash = 0 ORDER BY seqorder DESC,id DESC LIMIT 200')
		);
		header("Content-Type:text/xml; charset=utf-8");
		$this->load->view(TPL_FOLDER."news_rss",$data);
	}
	
	function ajax_make()
	{
		$md5key = $this->input->post('md5key');
		if($md5key != md5($this->config->item('md5_encode_key'))) die(0);
		$mitem=$this->input->post('mitem');
		if(!$mitem) die(0);
		switch($mitem)
		{
			case 'sitemap_baidu':
				$this->_sitemap_baidu();
				break;	
			case 'google':
				$this->_google();
				break;	
		}
	}
	
	function ads($id = 0)
	{
		if( ! $id) return ;
		$query = $this->db->get_where('ads',array('id'=>$id));
		if($query->num_rows() > 0)
		{
			$row = $query -> row();
		}
		if(isset($row))
		{
			if($row -> is_pic == 1)
			{
				$str = $this->load->view(TPL_FOLDER.'ads_img',array('ads'=>$row),true);
				header("Content-Type:application/x-javascript;charset=utf-8");
				echo "document.write('{$str}');";
			}
			else
			{
				$str = $this->load->view(TPL_FOLDER.'ads_flash',array('ads'=>$row),true);
				header("Content-Type:application/x-javascript;charset=utf-8");
				echo "document.write('{$str}');";
			}
		}
	}
	
	/*
	function _sitemap_baidu()
	{
		$data = array(
			'product'		=> $this->common_model->get_records('SELECT id,title,content,keyword,create_date FROM '.$this->db->dbprefix.'product WHERE is_trash = 0 ORDER BY seqorder DESC,id DESC LIMIT 200')
		);
		$html_data=$this->load->view(TPL_FOLDER."sitemap_baidu",$data,true);
		write_file('sitemap_baidu.xml',$html_data);
		die("1");	
	}
	
	function _google()
	{
		$data = array(
			'product'		=> $this->common_model->get_records('SELECT id,create_date FROM '.$this->db->dbprefix.'product WHERE is_trash = 0 ORDER BY seqorder DESC,id DESC LIMIT 200')
		);
		$html_data=$this->load->view(TPL_FOLDER."google",$data,true);
		write_file('google.xml',$html_data);
		die("1");	
	}
	*/
}
?>